<?php 

namespace app\admin\event;

use app\common\model\Category as CategoryModel;
use app\common\utils\JsonService;

class CategoryEvent{

    /*
    * 分类列表
    */
    public static function categoryList(){

        $category = CategoryModel::getTree();
        return $category;
    }


    /*
    * 新增分类
    */
    public static function createCategory($data){

        try {
            CategoryModel::create($data);
        } catch (\Exception $ex) {
            return JsonService::error($ex->getMessage());
        }
        return JsonService::success();
    }

    /*
    * 更新分类
    */
    public static function updateCategory($data){

        try {
            CategoryModel::updateOne($data, ['id' => $data['id']]);
        } catch (\Exception $ex) {
            return JsonService::error($ex->getMessage());
        }
        return JsonService::success();
    }


}

